import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/shims/dart_ui_real.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/img_util.dart';
import 'package:leader_help/value/topcolors.dart';

import 'key_point_small_logic.dart';

class KeyPointSmallPage extends StatefulWidget {
  const KeyPointSmallPage({Key? key}) : super(key: key);

  @override
  _KeyPointSmallPageState createState() => _KeyPointSmallPageState();
}

class _KeyPointSmallPageState extends State<KeyPointSmallPage> {
  final logic = Get.put(KeyPointSmallLogic());
  final state = Get.find<KeyPointSmallLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context, title: "微观问题"),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              width: Get.width,
              padding: EdgeInsets.only(left: 20.r, top: 20.r, right: 15.r, bottom: 20.r),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Row(
                    children: [
                      Image.asset("u650.png".imgPathTask, height: 70.r,),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("三全食品股份有限公司", style: TextStyle(color: TopColors.black_33, fontSize: 18, fontWeight: FontWeight.w600),),
                          SizedBox(height: 8.r,),
                          Text("中国速冻食品行业的开创者和领导者", style: TextStyle(color: TopColors.black_33, fontSize: 15),)
                        ],
                      )

                    ],
                  ),
                  SizedBox(height: 12.r,),
                  Row(
                    children: [
                      Container(
                        margin: EdgeInsets.only(left: 15.r),
                        padding: EdgeInsets.only(left: 10.r, top: 2.r, right: 10.r, bottom: 3.r),
                        decoration: BoxDecoration(
                          color: TopColors.gray_line,
                        ),
                        child: Text("河南-郑州", style: TextStyle(color: TopColors.black_66, fontSize: 13),),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 15.r),
                        padding: EdgeInsets.only(left: 10.r, top: 2.r, right: 10.r, bottom: 3.r),
                        decoration: const BoxDecoration(
                          color: Color(0xffF1A4AE),
                        ),
                        child: const Text("龙头企业", style: TextStyle(color: Color(0xffDD1E35), fontSize: 13),),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 15.r),
                        padding: EdgeInsets.only(left: 10.r, top: 2.r, right: 10.r, bottom: 3.r),
                        decoration: const BoxDecoration(
                            color: Color(0xffB8D5FF),

                        ),
                        child: const Text("上市企业", style: TextStyle(color: Color(0xff70abff), fontSize: 13),),
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              width: Get.width,
              margin: EdgeInsets.only(top: 5.r),
              padding: EdgeInsets.only(left: 20.r, top: 20.r, right: 15.r, bottom: 20.r),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Row(
                    children: [
                      Text("2011-09-09", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      SizedBox(width: 15.r,),
                      Text("融资金额：", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      Text("5.06亿人民币", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                    ],
                  ),
                  SizedBox(height: 5.r,),
                  Row(
                    children: [
                      SizedBox(width: 15.r,),
                      Text("股票增发", style: TextStyle(color: TopColors.black_33, fontSize: 15, fontWeight: FontWeight.w600),),
                    ],
                  ),
                  SizedBox(height: 10.r,),
                  Row(
                    children: [
                      Text("2008-02-20", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      SizedBox(width: 15.r,),
                      Text("融资金额：", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      Text("5.07亿人民币", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                    ],
                  ),
                  SizedBox(height: 5.r,),
                  Row(
                    children: [
                      SizedBox(width: 38.r,),
                      Text("IPO", style: TextStyle(color: TopColors.black_33, fontSize: 15, fontWeight: FontWeight.w600),),
                      SizedBox(width: 24.r,),
                      Text("估值金额：", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      Text("未披露", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              width: Get.width,
              margin: EdgeInsets.only(top: 5.r),
              padding: EdgeInsets.only(left: 20.r, top: 20.r, right: 15.r, bottom: 20.r),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text("企业问题", style: TextStyle(color: TopColors.black_33, fontSize: 17),),
                  Container(
                    margin: EdgeInsets.only(left: 15.r, top: 5.r),
                    child: Row(
                      children: [
                        const Icon(Icons.error, color: Colors.orange, size: 18,),
                        SizedBox(width: 8.r,),
                        const Text("净利润下降，缺乏创新产品",
                          style: TextStyle(color: Colors.orange, fontSize: 14),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),

                ],
              ),
            ),
            Container(
              width: Get.width,
              margin: EdgeInsets.only(top: 5.r),
              padding: EdgeInsets.only(left: 20.r, top: 20.r, right: 15.r, bottom: 20.r),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text("解决对策", style: TextStyle(color: TopColors.black_33, fontSize: 17),),
                      SizedBox(width: 10.r,),
                      Expanded(child: Text("智能推荐合适政策与案例", style: TextStyle(color: TopColors.black_66, fontSize: 17),)),
                      Text("更多", style: TextStyle(color: TopColors.black_66, fontSize: 14),),
                      Icon(Icons.arrow_forward_ios, size: 13, color: TopColors.black_66,)
                    ],
                  ),
                  ListView.builder(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemCount: state.type.length,
                    itemBuilder: (BuildContext context, int index) {
                      return solveListItem(index == 0 ? true : false, state.type[index], state.content[index]);
                    })
                ],
              ),
            ),
            Container(
              width: Get.width,
              margin: EdgeInsets.only(top: 15.r),
              padding: EdgeInsets.only(left: 20.r, top: 20.r, right: 15.r, bottom: 20.r),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Expanded(child: Text("相关问题", style: TextStyle(color: TopColors.black_33, fontSize: 17),)),
                      Text("更多", style: TextStyle(color: TopColors.black_66, fontSize: 14),),
                      Icon(Icons.arrow_forward_ios, size: 13, color: TopColors.black_66,)
                    ],
                  ),
                  ListView.separated(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemCount: state.type.length,
                    itemBuilder: (BuildContext context, int index) {
                      return relatedListItem(state.source[index], state.time[index]);
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return Divider(height: 1.0, color: TopColors.gray_line);
                    },
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<KeyPointSmallLogic>();
    super.dispose();
  }


  /// 解决对策
  Widget solveListItem (bool visible, String type, String content) {
    return Container(
      margin:EdgeInsets.fromLTRB(0.r, 5.r, 0.r, 5.r),
      decoration: BoxDecoration(
        color: TopColors.gray_line,
        borderRadius: BorderRadius.circular(5.r),
      ),
      child: Container(
        margin:EdgeInsets.all(2.r),
        padding: EdgeInsets.only(left: 5.r, top: 5.r, right: 5.r, bottom: 8.r),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.r),
        ),
        child: Stack(
          children: [
            Visibility(
              visible: visible,
              child:
              Align(alignment: Alignment.topRight, child: Image.asset("download.png".imgPathTask, height: 30.r),
              ),
            ),
            Row(
              children: [
                Expanded(
                  child: RichText(
                    text: TextSpan(
                        children: [
                          WidgetSpan(
                            child: Container(
                              decoration: BoxDecoration(
                                border: Border.all(color: TopColors.top_ju, width: 1),
                                borderRadius: BorderRadius.circular(2.r),
                              ),
                              child: Text(type, style: TextStyle(color: TopColors.top_ju, fontSize: 11),),
                            ),
                          ),
                          WidgetSpan(
                            child: SizedBox(width: 8.r,),
                          ),
                          TextSpan(text: content, style: TextStyle(color: TopColors.black_33, fontSize: 15,),)
                        ]
                    ),
                  ),
                ),
                Icon(Icons.arrow_forward_ios, size: 13, color: TopColors.black_33,)
              ],
            ),
          ],
        ),
      ),
    );
  }

  /// 相关问题
  Widget relatedListItem(String source, String time) {
    return Container(
      margin: EdgeInsets.only(left: 5.r, right: 5, top: 5.r, bottom: 5.r),
      child: Row(
        children: [
          Expanded(
            child: Column(
              children: [
                Text(
                  state.newContent[0],
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: TopColors.black_33, fontSize: 15),
                ),
                SizedBox(height: 8.r,),
                Row(
                  children: [
                    Expanded(child: Row(
                      children: [
                        Text("来源：", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                        Text(source, style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      ],
                    )),
                    Expanded(child: Row(
                      children: [
                        SizedBox(width: 30.r,),
                        Text("时间：", style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                        Text(time, style: TextStyle(color: TopColors.black_66, fontSize: 15),),
                      ],
                    )),
                  ],
                )

              ],
            ),
          ),
          Icon(Icons.arrow_forward_ios, size: 13, color: TopColors.black_66,),
        ],
      ),
    );
  }
}